<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 组合继承  (构造函数继承  + 原型继承 组合版)

    // 既实现了父类实例化对象相关属性和方法的继承  又实现了对父类原型对象上属性和方法的继承


    // 父类
    function Person(name, age) {
        // {}
        // {}[[prototype]] = Person.prototype;
        // this -> {}  Person在执行过程创建的实例化对象
        this.name = name;
        this.age = age;
    }

    Person.prototype.species = "human";
    Person.prototype.skill = function () {
        console.log("thinking!");
    }
    Person.prototype.say = function () {
        console.log(this.name, this.age);
    }

    var p = new Person("张三", 18);
    console.log(p);


    // 子类  (想让子类也拥有父类的属性和方法  实例化对象 + 原型对象)
    function ChinesePerson(name, age, hobby) {
        // debugger;
        // {}
        // {}[[prototype]] = ChinesePerson.prototype;
        // this -> {}  ChinesePerson在执行过程创建的实例化对象

        Person.call(this, name, age);

        this.hobby = hobby;
    }

    // 原本的
    // ChinesePerson.prototype = {constructor:ChinesePerson,[[prototype]]:Object.prototype}

    ChinesePerson.prototype = Object.create(Person.prototype);  // {[[Prototype]]:Person.prototype}
    ChinesePerson.prototype.constructor = ChinesePerson;

    ChinesePerson.prototype.speak = function () {
        console.log("chinese");
    }


    var cp = new ChinesePerson("张三", 18, "唱歌");
    console.log(cp);


    console.log(cp.species);
    console.log(cp.skill);
    console.log(cp.say);









</script>

</html>